const sequelize = require("../sequelize_ins");
const { DataTypes } = require("sequelize");
const { USER_TYPES } = require("../../sys_config");

const core = sequelize.define("user", {
  name: DataTypes.STRING,
  phone: DataTypes.STRING,
  type: { type: DataTypes.INTEGER, defaultValue: USER_TYPES.PATIENT },
  uuid: DataTypes.STRING,
  password: DataTypes.STRING,
});

module.exports = {
  core,

  async get_user_of_phone(phone) {
    return await this.core.findOne({ where: { phone } });
  },

  remove_sensitive(user) {
    delete user.password;
    delete user.uuid;
    return {
      id: user.id,
      name: user.name,
      phone: user.phone,
      type: user.type,
    };
  },
};
